<?php
/**
 * Candidat, extention de user avec les attributs de metiers, experience pro, compétences, permis, formations
 *
 * @author Gmax
 */
class modules_cvtheque_candidat extends modele_user{
    public $type = 'candidat';
    private $_metier = null;
    private $_mobilite = null;
    private $_decoulants = null;
    private $_competences = null;
    private $_formations = null;
    private $_experiences = null;
    private $_permis = null;
    
    public function __construct($id = null) {
        parent::__construct($id);
    }
    /**
     * renvoi le rayon de mobilite du candidat en km
     * @return int|null
     */
    public function getMobilite(){
        if($this->_mobilite===null){
            $sqlQuery = 'SELECT mobilite FROM '.PWE::getPrefixBdd().'mobilite WHERE user_id='.$this->getId().' LIMIT 1';
            $result = bdd_sql::doSql($sqlQuery,true);
            if($result['count']===1){
                $this->_mobilite = $result['results'][0]['mobilite'];
            }
        }
        return $this->_mobilite;
    }
    /**
     * défini le rayon de mobilite en km du candidat autour de sa ville
     * @param int $mobilite
     */
    public function setMobilite($mobilite=0){
        $this->_mobilite = $mobilite+0;
        $sqlQuery = 'REPLACE INTO '.PWE::getPrefixBdd().'mobilite (user_id,mobilite) VALUES ('.$this->getId().','.$this->getMobilite().')';
        bdd_sql::doSql($sqlQuery);
    }
    /**
     * renvoi le metier principal du candidat
     * @return \modules_cvtheque_metier
     */
    public function getMetier(){
        if($this->_metier === null){
            $sqlQuery = 'SELECT um.metier_id AS metier_id, um.duree AS duree FROM '.PWE::getPrefixBdd().'user_metier AS um WHERE um.user_id='.$this->getId().' AND um.is_principal=1 LIMIT 1';
            $result = bdd_sql::doSql($sqlQuery,true);
            if($result['count']===1){
                $metier_id = $result['results'][0]['metier_id'];
                $this->_metier = new modules_cvtheque_metier($metier_id);
                $this->_metier->setDuree($result['results'][0]['duree']);
            }
        }
        return $this->_metier;
    }
    /**
     * définir le metier principal du candidat
     * @param \modules_cvtheque_metier $metier
     */
    public function addMetier($metier){
        $old = null;
        if($this->getMetier()!==null){
            $old = $this->getMetier();
        }
        
        $retour = array('success'=>false,'error'=>'null');
        if($metier!==null&&$metier->getId()>0){
            $sqlQuery = 'REPLACE INTO '.PWE::getPrefixBdd().'user_metier (user_id,metier_id,is_principal,duree) ';
            $sqlQuery .= 'VALUES ('.$this->getId().','.$metier->getId().',1,'.$metier->getDuree().')';
            $result = bdd_sql::doSql($sqlQuery,false);
            if($result['count']>0){
                $retour['success'] = true;
                $this->_metier = $metier;
                if($old!==null){
                    $this->removeMetier($old);
                    $this->addDecoulant($old);
                }
            }else{
                $retour['error'] = bdd_sql::$LASTERROR;
            }
        }
        return $retour;
    }
    
    public function updateMetier($metier){
        if($metier!==null&&$metier->getId()>0){
            $sqlUpdate = 'UPDATE '.PWE::getPrefixBdd().'user_metier SET duree="'.$metier->getDuree().'" WHERE user_id='.$this->getId().' AND metier_id='.$metier->getId(); 
            bdd_sql::doSql($sqlUpdate,false);
        }
    }
    
    /**
     * supprimer le metier principal du cv
     * @param \modules_cvtheque_metier $metier
     */
    public function removeMetier($metier){
        if($metier!==null&&$metier->getId()>0){
            $sqlDelete = 'DELETE FROM '.PWE::getPrefixBdd().'user_metier WHERE metier_id='.$metier->getId().' AND user_id='.$this->getId();
            bdd_sql::doSql($sqlDelete,false);
        }
        $this->_metier = null;
    }
    /**
     * renvoi la liste des profils découlants,
     * métiers secondaires
     * @return \modules_cvtheque_metier
     */
    public function getDecoulants(){
        if($this->_decoulants === null){
            $retour = array();
            $sqlQuery = 'SELECT um.metier_id AS metier_id, um.duree AS duree FROM '.PWE::getPrefixBdd().'user_metier AS um WHERE um.user_id='.$this->getId().' AND um.is_principal=0';
            $result = bdd_sql::doSql($sqlQuery,true);
            if($result['count']>0){
                foreach ($result['results'] as $datas){
                    $metier = new modules_cvtheque_metier($datas['metier_id']);
                    $metier->setDuree($datas['duree']);
                    $retour[] = $metier;
                }
                $this->_decoulants = $retour;
            }
            return $retour;
        }else{
            return $this->_decoulants;
        }
    }
    /**
     * ajoute un metier découlant au cv
     * @param \modules_cvtheque_metier $metier
     * @return array [success,error]
     */
    public function addDecoulant($metier){
        $retour = array('success'=>false,'error'=>'null');
        if($metier!==null&&$metier->getId()>0){
            $sqlQuery = 'REPLACE INTO '.PWE::getPrefixBdd().'user_metier (user_id,metier_id,is_principal,duree) ';
            $sqlQuery .= 'VALUES ('.$this->getId().','.$metier->getId().',0,'.$metier->getDuree().')';
            $results = bdd_sql::doSql($sqlQuery,false);
            if($results['count']>0){
                $retour['success'] = true;
                if($this->_decoulants!==null){
                    $this->_decoulants[] = $metier;
                }
            }else{
                $retour['error'] = bdd_sql::$LASTERROR;
            }
        }
        return $retour;
    }
    /**
     * supprime un metier decoulant du cv
     * @param \modules_cvtheque_metier $metier
     * @return array [success,error]
     */
    public function removeDecoulant($metier){
        $retour = array('success'=>false,'error'=>'null');
        if($metier!==null&&$metier->getId()>0){
            $sqlDelete = 'DELETE FROM '.PWE::getPrefixBdd().'user_metier WHERE metier_id='.$metier->getId().' AND user_id='.$this->getId();
            $result = bdd_sql::doSql($sqlDelete,false);
            if($result['count']>0){
                $retour['success'] = true;
            }else{
                $retour['error'] = bdd_sql::$LASTERROR;
            }
        }
        return $retour;
    }

    /**
     * renvoi le tableau des compétence associées au candidat avec le niveau de maîtrise
     * @return \modules_cvtheque_competence
     */
    public function getCompetences(){
        if($this->_competences === null ){
            $sqlQuery = 'SELECT * FROM '.PWE::getPrefixBdd().'user_competence WHERE user_id='.$this->getId();
            $retour = array();
            $results = bdd_sql::doSql($sqlQuery, true);
            if($results['count']>0){
                foreach($results['results'] as $data){
                    $comp = new modules_cvtheque_competence($data['competence_id']);
                    $comp->setNiveauId($data['niveau_id']);
                    $retour[] = $comp;
                }
                $this->_competences = $retour;
            }
            return $retour;
        }else{
            return $this->_competences;
        }
    }
    /**
     * ajoute une compétence au cv
     * @param \modules_cvtheque_competence $competence
     * @param int $niveau_id
     * @return array [success,error]
     */
    public function addCompetence($competence,$niveau_id=3){
        $retour = array('success'=>false,'error'=>'null');
        if($competence!==null&&$competence->getId()>0){
            $sqlQuery = 'REPLACE INTO '.PWE::getPrefixBdd().'user_competence (user_id,competence_id,niveau_id) VALUES ('.$this->getId().','.$competence->getId().','.$niveau_id.')';
            $results = bdd_sql::doSql($sqlQuery,false);
            if($results['count']>0){
                $retour['success'] = true;
                if($this->_competences === null ){
                    $this->_competences = array($competence);
                }else{
                    $this->_competences[] = $competence;
                }
            }else{
                $retour['error'] = bdd_sql::$LASTERROR;
            }
        }
        return $retour;
    }
    /**
     * supprime une compétence du cv
     * @param \modules_cvtheque_competence $competence
     * @return array [success,error]
     */
    public function removeCompetence($competence){
        $retour = array('success'=>false,'error'=>'null');
        if($competence!==null&&$competence->getId()>0){
            $sqlQuery = 'DELETE FROM '.PWE::getPrefixBdd().'user_competence WHERE user_id='.$this->getId().' AND competence_id='.$competence->getId();
            $results = bdd_sql::doSql($sqlQuery,false);
            if($results['count']>0){
                $retour['success'] = true;
                if($this->_competences !== null ){
                    $idx = array_search($competence, $this->_competences);
                    if($idx!==false){
                        unset($this->_competences[$idx]);
                    }
                }
            }else{
                $retour['error'] = bdd_sql::$LASTERROR;
            }
        }
        return $retour;
    }
    
    /**
     * renvoi le tableau des permis associées au candidat
     * @return \modules_cvtheque_permis
     */
    public function getPermis(){
        if($this->_permis === null ){
            $sqlQuery = 'SELECT ';
            $sqlQuery .= 'up.date_fin AS date_fin, up.permis_id AS permis_id ';
            $sqlQuery .= 'FROM '.PWE::getPrefixBdd().'user_permis AS up ';
            $sqlQuery .= 'WHERE up.user_id='.$this->getId();

            $retour = array();

            $results = bdd_sql::doSql($sqlQuery, true);
            if($results['count']>0){
                foreach($results['results'] as $datas){
                    $permis = new modules_cvtheque_permis($datas['permis_id']);
                    $permis->setDateFin($datas['date_fin']);
                    $retour[] = $permis;
                }                
                $this->_permis = $retour;
            }
            return $retour;
        }else{
            return $this->_permis;
        }
    }
    /**
     * ajoute un perim au cv
     * @param \modules_cvtheque_permis $permis
     * @return array [success,error]
     */
    public function addPermis($permis){
        $retour = array('success'=>false,'error'=>'null');
        if($permis!==null&&$permis->getId()>0){
            $sqlQuery = 'INSERT INTO '.PWE::getPrefixBdd().'user_permis (user_id,permis_id,date_fin) VALUES ('.$this->getId().','.$permis->getId().',"'.$permis->getDateFin().'")';
            $result = bdd_sql::doSql($sqlQuery,false);
            if($result['count']>0){
                $retour['success'] = true;
                if($this->_permis === null ){
                    $this->_permis = array($permis);
                }else{
                    $this->_permis[] = $permis;
                }
            }else{
                $retour['error'] = bdd_sql::$LASTERROR;
            }
        }
        return $retour;
    }
    /**
     * met à jour un perim au cv
     * @param \modules_cvtheque_permis $permis
     * @return array [success,error]
     */
    public function updatePermis($permis){
        $retour = array('success'=>false,'error'=>'null');
        if($permis!==null&&$permis->getId()>0){
            $sqlQuery = 'UPDATE '.PWE::getPrefixBdd().'user_permis SET date_fin="'.$permis->getDateFin().'" WHERE user_id='.$this->getId().' AND permis_id='.$permis->getId();
            $results = bdd_sql::doSql($sqlQuery,false);
            if($results['count']>0){
                $retour['success'] = true;
            }else{
                $retour['error'] = bdd_sql::$LASTERROR;
            }
        }
        return $retour;
    }
    /**
     * supprime un permi du cv
     * @param \modules_cvtheque_permis $permis
     * @return array [success,error]
     */
    public function removePermis($permis){
        $retour = array('success'=>false,'error'=>'null');
        if($permis!==null&&$permis->getId()>0){
            $sqlQuery = 'DELETE FROM '.PWE::getPrefixBdd().'user_permis WHERE user_id='.$this->getId().' AND permis_id='.$permis->getId();
            $results = bdd_sql::doSql($sqlQuery,false);
            if($results['count']>0){
                $retour['success'] = true;
                if($this->_permis !== null ){
                    $idx = array_search($permis, $this->_permis);
                    if($idx!==false){
                        unset($this->_permis[$idx]);
                    }
                }
            }else{
                $retour['error'] = bdd_sql::$LASTERROR;
            }
        }
        return $retour;
    }
    /**
     * renvoi la liste des formations par ordre chronologique
     * @param string $order ordonner par date croissante 'ASC' ou decroissante 'DESC' = default
     * @return \modules_cvtheque_formation
     */
    public function getFormations($order='DESC'){
        if($this->_formations === null ){
            $sqlQuery = 'SELECT ';
            $sqlQuery .= 'f.id AS id ';
            $sqlQuery .= 'FROM '.PWE::getPrefixBdd().'formation AS f ';
            $sqlQuery .= 'WHERE f.user_id='.$this->getId();
            $sqlQuery .= ' ORDER BY f.date_debut '.$order;
            
            $retour = array();

            $results = bdd_sql::doSql($sqlQuery, true);
            if($results['count']>0){
                foreach($results['results'] as $datas){
                    $formation = new modules_cvtheque_formation($datas['id']);
                    $retour[] = $formation;
                }
                
                $this->_formations = $retour;
            }
            return $retour;
        }else{
            return $this->_formations;
        }
    }
    /**
     * renvoi la liste des experiences par ordre chronologique
     * @param string $order ordonner par date croissante 'ASC' ou decroissante 'DESC' = default
     * @return \modules_cvtheque_experience
     */
    public function getExperiences($order='DESC'){
        if($this->_experiences === null ){
            $sqlQuery = 'SELECT ';
            $sqlQuery .= 'e.id AS id ';
            $sqlQuery .= 'FROM '.PWE::getPrefixBdd().'experience AS e ';
            $sqlQuery .= 'WHERE e.user_id='.$this->getId();
            $sqlQuery .= ' ORDER BY e.date_debut '.$order;
            
            $retour = array();

            $results = bdd_sql::doSql($sqlQuery, true);
            if($results['count']>0){
                foreach($results['results'] as $datas){
                    $experience = new modules_cvtheque_experience($datas['id']);
                    $retour[] = $experience;
                }
                
                $this->_experiences = $retour;
            }
            return $retour;
        }else{
            return $this->_experiences;
        }
    }
    
    public function getDatas($input = false) {
        $datas = parent::getDatas($input);
        $datas['mobilite'] = $this->getMobilite();
        
        return $datas;
    }
    
    /**
     * renvoi le media_id du document cv du candidat
     * @return int
     */
    public function getDocumentId(){
        $sqlQuery = 'SELECT id FROM '.modele_media::getTable().' WHERE title="cv_candidat_'.$this->getId().'" LIMIT 1';
        $result = $this->_getOneResult($sqlQuery);
        $retour = 0;
        if($result){
            $retour =  $result['id'];
        }
        return $retour;
    }
    /**
     * renvoi le media cv du candidat
     * @return \modele_media|null
     */
    public function getDocument(){
        $mediaId = $this->getDocumentId();
        if($mediaId>0){
            return new modele_media($mediaId);
        }else{
            return null;
        }
    }
    
    /**
     * passe le postulant en candidat inscrt dans la cvtheque en mode non publié
     */
    public function valider(){
        $this->_is_banned = 1;
        $this->_is_verif = 1;
        $sqlValide = 'UPDATE '.self::getTable().' SET ';
        $sqlValide .= 'is_banned=1, is_verif=1 ';
        $sqlValide .= 'WHERE id='.$this->getId().' LIMIT 1';
        
        bdd_sql::doSql($sqlValide,false);
        return array('success'=>true,'datas'=>array());
    }
    
    /**
     * supprime le candidat
     * @return array
     */
    public function delete(){ 
        $sqlQueryMob = 'DELETE FROM '.PWE::getPrefixBdd().'mobilite WHERE user_id='.$this->getId().' LIMIT 1';
        bdd_sql::doSql($sqlQueryMob);

        if($this->getAdresse()!==null)$this->getAdresse()->delete();
        if($this->getMedia()!==null)$this->getMedia()->delete();
        $this->removeMetier($this->getMetier());
        foreach($this->getCompetences() as $competence){
            $this->removeCompetence($competence);
        }
        foreach($this->getPermis() as $permi){
            $this->removePermis($permi);
        }
        foreach($this->getDecoulants() as $metier){
            $this->removeDecoulant($metier);
        }
        foreach($this->getExperiences() as $exp){
            $exp->delete();
        }
        foreach($this->getFormations() as $form){
            $form->delete();
        }
        
        $sqlQuery = 'DELETE FROM '.self::getTable().' WHERE id='.$this->getId().' LIMIT 1';
        $result = bdd_sql::doSql($sqlQuery);
        
        return array('success'=>($result['count']>0)?true:false,'datas'=>array());
    }
    /* methodes statiques */
    
    /**
     * renvoi la liste des candidats inscrits
     * @param int $start
     * @param int $limit
     * @param boolean $public condidat disponible
     * @param boolean $valide candidat en CVthèque
     * @param string $orderBy colonne de tri
     * @param string $dir ASC/DESC sens de tri
     * @return \modules_cvtheque_candidat
     */
    public static function getListe($start=0,$limit=0,$public=false,$valide=true,$orderBy='nom',$dir='DESC'){
        $sqlQuery = 'SELECT c.id FROM '.self::getTable().' AS c WHERE c.user_level_id=4';
        if($valide){
            $sqlQuery .= ' AND c.is_verif=1';
        }else{
            $sqlQuery .= ' AND c.is_verif=0';
        }
        if($public){
            $sqlQuery .= ' AND c.is_banned=0';
        }
        $sqlQuery .= ' ORDER BY c.'.$orderBy.' '.$dir;
        
        
        if($limit>0){
            $sqlQuery .= ' LIMIT '.$start.','.$limit;
        }
        $retour = array();
        $results = bdd_sql::doSql($sqlQuery,true,true);
        if($results['count']>0){
            foreach ($results['results'] as $data){
                $candidat = new modules_cvtheque_candidat($data['id']);
                $retour[] = $candidat;
            }
        }
        return $retour;
    }
    
    /**
     * renvoi le nombre total de candidats inscrits
     * @param boolean $public condidat disponible
     * @param boolean $valide candidat en CVthèque
     * @return int
     */
    public static function getNombre($public=false,$valide=true){
        $sqlQuery = 'SELECT COUNT(c.id) AS nombre FROM '.self::getTable().' AS c WHERE c.user_level_id=4';
        if($valide){
            $sqlQuery .= ' AND c.is_verif=1';
        }else{
            $sqlQuery .= ' AND c.is_verif=0';
        }
        if($public){
            $sqlQuery .= ' AND c.is_banned=0';
        }
        $result = bdd_sql::doSql($sqlQuery);
        $nombre = 0;
        if($result['count']>0){
            $nombre = $result['results'][0]['nombre'];
        }
        
        return $nombre;
    }
    
    /**
     * 
     * @param type $params
     * @return int|array
     */
    public static function countSearchCandidat($params=array()){
        
        if(isset($params['get_results'])&&$params['get_results']===1){
            $query = 'SELECT c.id AS id ';
        }else{
            $query = 'SELECT COUNT(c.id) AS nombre ';
        }
        
        if(isset($params['lat'])&&isset($params['lng'])){
            $query .= ', ((6366*ACOS(COS(RADIANS('.$params['lat'].'))*COS(RADIANS(adr.lat))*COS(RADIANS(adr.lng)-RADIANS('.$params['lng'].'))+SIN(RADIANS('.$params['lat'].'))*SIN(RADIANS(adr.lat))))) AS distance ';
        }
        
        // from
        $query .= 'FROM '.self::getTable().' AS c ';
        
        // jointures
        if(isset($params['lat'])&&isset($params['lng'])){
            $query .= 'LEFT JOIN '.modele_adresse::getTable().' AS adr ON c.adresse_id=adr.id ';
            $query .= 'LEFT JOIN '.PWE::getPrefixBdd().'mobilite AS cm ON cm.user_id=c.id ';
        }
        
        // where
        $query .= 'WHERE c.user_level_id=4 AND ';
        if(count($params)>0){
            // profil valide
            if(isset($params['public'])&&$params['public']===true){
                $query .= 'c.is_banned=0 AND ';
            }
            // metier_id
            if(isset($params['metier_id'])&&$params['metier_id']>0){
                $query .= 'c.id IN( SELECT um.user_id FROM '.PWE::getPrefixBdd().'user_metier AS um WHERE um.user_id=c.id AND um.metier_id='.$params['metier_id'];
                if($params['is_principal']===1) $query .= ' AND um.is_principal='.$params['is_principal'];
                $query .= ' ) AND ';
            }elseif(isset($params['metier'])&&trim($params['metier'])!=""){
                $query .= 'c.id IN(';
                    $query .= 'SELECT um.user_id FROM '.PWE::getPrefixBdd().'user_metier AS um ';
                    $query .= 'WHERE um.metier_id IN(';
                        $query .= 'SELECT metier.id FROM '.PWE::getPrefixBdd().'metier AS metier ';
                        $query .= 'WHERE ';
                        $query .= 'metier.nom LIKE "%'.encoding::fixUTF8(addslashes(htmlentities(encoding::toUTF8($params['metier'])))).'%" ';
                        $query .= 'OR metier.nom LIKE "%'.encoding::fixUTF8(addslashes(htmlentities(encoding::toUTF8(tools_convert::slug($params['metier']))))).'%" ';
                    $query .= ')';
                if($params['is_principal']===1){
                    $query .= ' AND um.is_principal='.$params['is_principal'];
                }
                $query .= ' ) AND ';
            }
            
            // compétence
            if(isset($params['competence_id'])&&$params['competence_id']>0){
                $query .= 'c.id IN( SELECT uc.user_id FROM '.PWE::getPrefixBdd().'user_competence AS uc WHERE uc.user_id=c.id AND uc.competence_id='.$params['competence_id'].' )>0 AND ';
            }
            
            if(isset($params['lat'])&&isset($params['lng'])){
                $query .= 'adr.lat<>0 AND adr.lng<>0 AND ';
                $query .= '((6366*ACOS(COS(RADIANS('.$params['lat'].'))*COS(RADIANS(adr.lat))*COS(RADIANS(adr.lng)-RADIANS('.$params['lng'].'))+SIN(RADIANS('.$params['lat'].'))*SIN(RADIANS(adr.lat))))) < (cm.mobilite+5) AND ';
            }
        }
        $query = substr($query, 0, -4);
        
        // order
        if(isset($params['get_results'])&&$params['get_results']===1&&isset($params['lat'])&&isset($params['lng'])){
            $query .= 'ORDER BY distance ';
        }
        
        // limit
        $start = (isset($params['start'])&&$params['start']>0)?$params['start']:0;
        $limit = (isset($params['limit'])&&$params['limit']>0)?$params['limit']:0;
        
        if($limit>0){
            $query .= 'LIMIT '.$start.','.$limit;
        }
        
        // echo '------------------'.$query.'------------------';
        
        // dosql
        $retour = 0;
        $results = bdd_sql::doSql($query);
        
        if($results['count']>0){
            if(isset($params['get_results'])&&$params['get_results']===1){
                $retour = $results['results'];
            }else{
                $retour = $results['results'][0]['nombre'];
            }
        }
        return $retour;
    }
    
    /**
     * 
     * @param int $start
     * @param int $limit
     * @param array $params[lat,lng,metier_id]
     * @return \modules_cvtheque_candidat
     */
    public static function searchCandidat($start=0,$limit=0,$params=array()){
        $params['get_results'] = 1;
        $params['start'] = $start;
        $params['limit'] = $limit;
        
        $retour = array();
        
        $results = self::countSearchCandidat($params);
        if(is_array($results)){
            foreach ($results as $data){
                $retour[] = new modules_cvtheque_candidat($data['id']);
            }
        }
        return $retour;
    }
    
    /**
     * recherche les candidats dont les coordonnées lat-lng rechercher sont dans son périmètre de mobilité
     * @param float $lat
     * @param float $lng
     */
    public static function getCandidatInPerimetre($lat,$lng){
        $query = 'SELECT c.id AS id ';
        $query .= ', ((6366*ACOS(COS(RADIANS('.$lat.'))*COS(RADIANS(adr.lat))*COS(RADIANS(adr.lng)-RADIANS('.$lng.'))+SIN(RADIANS('.$lat.'))*SIN(RADIANS(adr.lat))))) AS distance ';
        $query .= 'FROM '.self::getTable().' AS c ';
        $query .= 'LEFT JOIN '.modele_adresse::getTable().' AS adr ON c.adresse_id=adr.id ';
        $query .= 'LEFT JOIN '.PWE::getPrefixBdd().'mobilite AS cm ON cm.user_id=c.id ';
        $query .= 'WHERE c.user_level_id=4 AND adr.lat<>0 AND adr.lng<>0 AND ';
        $query .= '((6366*ACOS(COS(RADIANS('.$lat.'))*COS(RADIANS(adr.lat))*COS(RADIANS(adr.lng)-RADIANS('.$lng.'))+SIN(RADIANS('.$lat.'))*SIN(RADIANS(adr.lat))))) < cm.mobilite ';
        $query .= 'ORDER BY distance';
        
        $retour = array();
        
        $results = bdd_sql::doSql($query);
        if($results['count']>0){
            foreach($results['results'] as $data){
                $retour[] = new modules_cvtheque_candidat($data['id']);
            }
        }
        return $retour;
    }
}
